package com.example.flower_shop.service;

import com.example.flower_shop.entity.CartItem;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface CartService extends BaseService<CartItem, Long> {

    List<CartItem> findByUserId(Long userId);

    CartItem addToCart(Long userId, Long productId, Integer quantity);

    CartItem updateQuantity(Long userId, Long productId, Integer quantity);

    /**
     * 从购物车中移除商品
     * 
     * @param userId     用户ID
     * @param cartItemId 购物车项ID
     */
    void removeFromCart(Long userId, Long cartItemId);

    void clearCart(Long userId);

    int countByUserId(Long userId);

    boolean checkProductInCart(Long userId, Long productId);

    void checkCartItemBelongsToUser(Long cartItemId, Long userId);

    @Transactional
    void checkAndUpdateCartItems(Long userId);
}